package com.databaseconnectionmobilapi.aop;

import com.databaseconnectionmobilapi.constant.Storage;
import com.databaseconnectionmobilapi.exception.LinkLimitReachedException;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * @author Fall
 */
@Aspect
@Component
public class EstablishConnectionAspect {
    @Pointcut("execution(public * com.databaseconnectionmobilapi.util.util.DbUtil.*())")
    public void pointCut(){

    }

    @Before("pointCut()")
    public void before(JoinPoint joinPoint) throws LinkLimitReachedException {
        if (Storage.CONNECTIONS > 10) {
            throw new LinkLimitReachedException();
        }
    }
}
